<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <h1>正在学习:{{msg}}</h1>
        <button v-on:click="change()">切换</button>
    </div>
    
    <script src="plugins/vue2.js"></script>
    <script>
        new Vue({
            el:'#app',
            data:function(){
                return{
                    isJava:true,
                    msg:'Java'
                }
            },

            methods:{
                change(){
                    this.isJava = !this.isJava;
                }
            },

            //监听器
            watch:{
                isJava:{
                    immediate:true,
                    handler(newVal){  // newVal是isJava改变后的值
                        this.msg=newVal?'Java':'vue2';  // 注意this
                    }
                }
            }
            
        });
    </script>
</body>
</html>